package com.wanwen.controller;

import java.util.ArrayList;
import java.util.List;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.wanwen.dto.EchartsDto;
import com.wanwen.entity.Student;
import com.wanwen.mapper.StudentMapper;

@RestController
@RequestMapping("/echarts")
public class EchartsController {
	  @Autowired
	  private StudentMapper studentMapper;
	  /**
		 * 查询所有地区数量
		 * 
		 * @param usc 条件对象
		 * @return
		 */
	  @RequestMapping("/getAll")
		public Object getAll() {
			// 封装条件查询构造器
			QueryWrapper<Student> wrapper = new QueryWrapper<Student>();
			wrapper.select("COUNT(id) as id,Address");
			wrapper.groupBy("Address");
			List<Student> selectList = studentMapper.selectList(wrapper);
			//封装图表对象
			List<EchartsDto> list = new ArrayList<EchartsDto>();
			for (Student student : selectList) {
				EchartsDto EchartsDto = 
						new EchartsDto(student.getId(), student.getAddress());
				list.add(EchartsDto);
			}
			return list;
		}
	  
	  /**
		 * 查询所有地区数量
		 * 
		 * @param usc 条件对象
		 * @return
		 */
	  @RequestMapping("/getAlls")
		public Object getAlls() {
			// 封装条件查询构造器
			QueryWrapper<Student> wrapper = new QueryWrapper<Student>();
			wrapper.select("DATE_FORMAT( creat_time, \"%m月\") remark,COUNT(id) id ");
			wrapper.groupBy("DATE_FORMAT( creat_time, \"%m月\")"); 
			List<Student> selectList = studentMapper.selectList(wrapper);
			System.err.println(selectList);
			//封装图表对象
			List<EchartsDto> list = new ArrayList<EchartsDto>();
			for (Student student : selectList) {
				System.err.println(student.getRemark());
				EchartsDto EchartsDto = 
						new EchartsDto(student.getId(), student.getRemark());
				list.add(EchartsDto);
			}
			System.err.println(list);
			return list;
		}
}
